<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>
            <el-button v-if="isAuth('kernel:dictionary:parameter:form')" type="success" icon="Plus" @click="router.push({ name: 'kernel_dictionary_parameter_form', query: { dictionary_id: dataForm.dictionary_id } })">
              {{ i18n('common.create') }}
            </el-button>
          </div>
        </div>
        <div class="admin_main_block_right">
          <div>
            <el-button v-if="isAuth('kernel:dictionary:parameter:delete')" type="danger" icon="Delete" @click="deleteHandle()">
              {{ i18n('common.batch_delete') }}
            </el-button>
          </div>
          <div class="mr10">
            <el-button icon="Back" @click="router.push({ name: 'kernel_dictionary_list' })">
              {{ $t('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_main_block_select">
        <div class="input">
          <el-input v-model="dataForm.title" :placeholder="i18n('common.please_input') + i18n('kernel.dictionary.parameter.title')" clearable>
          </el-input>
        </div>
        <div class="input">
          <el-button icon="Search" @click="getDataList(true)">
            {{ i18n('common.search') }}
          </el-button>
        </div>
      </div>

      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" stripe>
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" :label="i18n('common.id')" width="70px">
          </el-table-column>

          <el-table-column prop="title" :label="i18n('kernel.dictionary.parameter.title')" min-width="140">
          </el-table-column>

          <el-table-column prop="value" :label="i18n('kernel.dictionary.parameter.value')" min-width="240">
          </el-table-column>

          <el-table-column prop="sort" :label="i18n('common.sort')" width="80">
          </el-table-column>

          <el-table-column prop="create_time" :label="i18n('common.create_time')" width="160">
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="200">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('kernel:dictionary:parameter:form')"
                type="primary"
                icon="Edit"
                @click="router.push({ name: 'kernel_dictionary_parameter_form', query: { dictionary_id: dataForm.dictionary_id, id: scope.row.id } })">
                {{ i18n('common.update') }}
              </el-button>

              <el-button
                v-if="isAuth('kernel:dictionary:parameter:delete')"
                type="danger"
                icon="Delete"
                @click="deleteHandle(scope.row.id)">
                <span class="delete">{{ i18n('common.delete') }}</span>
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="dictionary-parameter-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('dictionary/parameter')
  const dataForm = reactive([
    'dictionary_id',
    'title',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    deleteHandle,
  } = useTable(model.value, dataForm)

  onMounted(() => {
    dataForm.dictionary_id = query.dictionary_id

    getDataList(model)
  })
</script>
